package com.lizhi.menu.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lizhi.menu.Dto.CommodityDto;
import com.lizhi.menu.domain.Commodity;
import com.lizhi.menu.mapper.CommodityMapper;
import com.lizhi.menu.service.ICommodityService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 商品Service业务层处理
 *
 * @author lizhi
 * @date 2023-05-18
 */
@Service
@RequiredArgsConstructor
public class CommodityServiceImpl implements ICommodityService {
    private final CommodityMapper commodityMapper;

    /**
     * 查询商品
     *
     * @param id 商品主键
     * @return 商品
     */
    @Override
    public Commodity selectCommodityById(String id) {
        return commodityMapper.selectById(id);
    }

    /**
     * 查询商品列表
     *
     * @param commodity 商品
     * @return 商品
     */
    @Override
    public Page<Commodity> selectCommodityList(CommodityDto commodity) {
        return commodityMapper.selectCommodityList(commodity.createPage(),commodity);
    }

    /**
     * 新增商品
     *
     * @param commodity 商品
     * @return 结果
     */
    @Override
    public int insertCommodity(Commodity commodity) {
        commodity.setCreateTime(LocalDateTime.now());
        return commodityMapper.insertCommodity(commodity);
    }

    /**
     * 修改商品
     *
     * @param commodity 商品
     * @return 结果
     */
    @Override
    public int updateCommodity(Commodity commodity) {
        commodity.setUpdateTime(LocalDateTime.now());
        return commodityMapper.updateCommodity(commodity);
    }

    /**
     * 批量删除商品
     *
     * @param ids 需要删除的商品主键
     * @return 结果
     */
    @Override
    public int remove(List<String> ids) {
        return commodityMapper.deleteCommodityByIds(ids);
    }

    /**
     * 删除商品信息
     *
     * @param id 商品主键
     * @return 结果
     */
    @Override
    public int remove(String id) {
        return commodityMapper.deleteCommodityById(id);
    }
}
